import request from '@/utils/request'

import MescrollMixins from '@/components/mescroll-uni/mescroll-mixins';
const ListMixin = {
	mixins:[MescrollMixins],
	data(){
		return{
			pageOptions:{
				pageSize:50,
				current:1
			},
		} 
	},
	created(){
	},
	onShow(){
		if(!this.notRunShow){
			this.getList()
		}
	},
	computed: {
		top() {
			return  this.CustomBar + 92 
		},
	},
	methods:{
		
		/**
		 * 加载页面数据
		 * @param {Object} callback
		 */
		getList(callback) {
		  let params = this.getQueryParams()
			request
			request(params)
		    .then(result => {
		      this[this.resultKey] = result.data[this.resultKey]
		      // 设置顶部导航栏栏
		    })
		    .finally(() => callback && callback())
		},
		getQueryParams(){
			let params = Object.assign({},this.queryParams,this.pageOptions)
			return params
		},
		
		/**
		 * 跳转文章详情页
		 * @id 对应的id
		 * @key page取值
		 */
		onTargetDetail(id,key) {
		  this.$navTo(this.pages[key] + id)
		},
		
		/**
		 * 
		 * @param {number} page 
		 * 获取列表数据
		 */
		 loadData(page) {
			 console.log(2222);
			this.pageOptions.current = page.num
			
			let params = this.getQueryParams()
			Api[this.url.list](params)
			  .then(result => {
				let data = result.data[this.resultKey]
				//设置列表数据
				if (result.code == 200) {
					for (let annItem of data) {
						this[this.resultKey].push(annItem)
					}
				}
				if (page.num == 1) {
					this[this.resultKey] = []; //如果是第一页需手动制空列表
					this[this.resultKey] = this[this.resultKey].concat(result.data[this.resultKey]); //追加新数据
				}
				this.mescroll.endBySize(data.length,result.data.total);
				// 设置顶部导航栏栏
			  })
		 }
	}
}
export default ListMixin